package com.example.jmeter.enums;

import com.example.jmeter.entity.TestPlan;
import com.example.jmeter.entity.ThreadGroup;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

/**
 * @program: spring-agent
 * @description:
 * @author: zt22328
 * @create: 2023-04-21 14:21
 **/
public enum JmxTemplate {

    HTTP{
        @Override
        public void checkTestPlan(TestPlan testPlan) {
            checkCommon(testPlan);
            for (ThreadGroup threadGroup : testPlan.getThreadGroups()) {
                Assert.isTrue(!CollectionUtils.isEmpty(threadGroup.getHttpSamplers()), "Http请求不能为空");
            }
        }
    },

    ;

    private static void checkCommon(TestPlan testPlan) {
        Assert.notNull(testPlan, "测试计划不能为空");
        Assert.hasText(testPlan.getName(), "测试计划名称不能为空");
        Assert.notNull(testPlan.getAggregateReport(), "聚合报告不能能为空");
        Assert.isTrue(!CollectionUtils.isEmpty(testPlan.getThreadGroups()), "线程组不能为空");
    }

    public String getTemplate() {
        return this.name().toLowerCase() + ".ftl";
    }

    public abstract void checkTestPlan(TestPlan testPlan);
}
